package com.director.hibernate;

import com.director.core.ParameterFactory;
import org.hibernate.SessionFactory;

import java.io.Serializable;

/**
 * @author Simone Ricciardi
 * @version 1.0, 10/16/2011
 */
public abstract class LoadByIdParameterFactory<T extends Serializable> implements ParameterFactory<T> {

   private SessionFactory sessionFactory;

   public LoadByIdParameterFactory(SessionFactory sessionFactory) {
      this.sessionFactory = sessionFactory;
   }

   @Override
   public abstract Class<T> getInputType();

   @Override
   public Object create(Class type, T id) {
      return sessionFactory.getCurrentSession().load(type, id);
   }
}
